package edu.online.dal;

import edu.online.entity.CourseEntity;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface CourseEntityMapper {
    @Delete({
        "delete from course",
        "where CourseID = #{courseid,jdbcType=CHAR}"
    })
    int deleteByPrimaryKey(String courseid);

    @Insert({
        "insert into course (CourseID, CourseName, ",
        "SubID, LessonNum, ",
        "Price, Comment)",
        "values (#{courseid,jdbcType=CHAR}, #{coursename,jdbcType=VARCHAR}, ",
        "#{subid,jdbcType=CHAR}, #{lessonnum,jdbcType=SMALLINT}, ",
        "#{price,jdbcType=SMALLINT}, #{comment,jdbcType=VARCHAR})"
    })
    int insert(CourseEntity record);

    @InsertProvider(type=CourseEntitySqlProvider.class, method="insertSelective")
    int insertSelective(CourseEntity record);

    @Select({
        "select",
        "CourseID, CourseName, SubID, LessonNum, Price, Comment",
        "from course",
        "where CourseID = #{courseid,jdbcType=CHAR}"
    })
    @Results({
        @Result(column="CourseID", property="courseid", jdbcType=JdbcType.CHAR, id=true),
        @Result(column="CourseName", property="coursename", jdbcType=JdbcType.VARCHAR),
        @Result(column="SubID", property="subid", jdbcType=JdbcType.CHAR),
        @Result(column="LessonNum", property="lessonnum", jdbcType=JdbcType.SMALLINT),
        @Result(column="Price", property="price", jdbcType=JdbcType.SMALLINT),
        @Result(column="Comment", property="comment", jdbcType=JdbcType.VARCHAR)
    })
    CourseEntity selectByPrimaryKey(String courseid);

    @UpdateProvider(type=CourseEntitySqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(CourseEntity record);

    @Update({
        "update course",
        "set CourseName = #{coursename,jdbcType=VARCHAR},",
          "SubID = #{subid,jdbcType=CHAR},",
          "LessonNum = #{lessonnum,jdbcType=SMALLINT},",
          "Price = #{price,jdbcType=SMALLINT},",
          "Comment = #{comment,jdbcType=VARCHAR}",
        "where CourseID = #{courseid,jdbcType=CHAR}"
    })
    int updateByPrimaryKey(CourseEntity record);
}